//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader
{
	import mx.managers.ToolTipManager;
	
	import org.puremvc.as3.multicore.interfaces.IFacade;
	import org.puremvc.as3.multicore.patterns.facade.Facade;
	
	import reader.controller.AboutMeCommand;
	import reader.controller.AutoUpdateCommand;
	import reader.controller.CloseCommand;
	import reader.controller.DataErrorCommand;
	import reader.controller.InitDataCommand;
	import reader.controller.LoginCommand;
	import reader.controller.LoginOutCommand;
	import reader.controller.OpenExplorerCommand;
	import reader.controller.OpenWriterCommand;
	import reader.controller.ScreenCommand;
	import reader.controller.SettingPanelCommand;
	import reader.controller.StartUpCommand;
	import reader.controller.TrayCommand;
	import reader.controller.UserConfirmCommand;
	import reader.model.vo.*;
	import reader.view.components.HtmlToolTip;
	
	public class ApplicationFacade extends Facade implements IFacade
	{
		//Facade name
		public static const NAME:String = "ApplicationFacade";
		
		//////////////////////////////////////////////////////////////////////////////
		//Notification name constants
		
		//screen
		public static const CHANGE_SCREEN:String		= "changeScreen";
		public static const SCREEN_CHANGED:String		= "screenChanged";
		
		public static const FETCH_COUNTS:String			= "fetchCount";
		
		//app setting
		public static const UPDATE_READER:String		= "updateReader";
		public static const STARTUP:String				= "startUp";
		public static const TRAY_DOCK:String			= "trayDock";
		public static const SYS_DOCKED:String			= "sysDocked";
		public static const SYS_COMMON:String			= "sysCommon";
		public static const CLOSE_WINDOW:String			= "closeWindow";
		public static const RESOURCE_LOAD:String		= "resourceLoad";
		public static const REQUEST_USERCONFIRM:String	= "requestUserConfirm";
		public static const SHOW_ABOUT:String			= "showAbout";
		
		//login and register		
		public static const LOGIN:String				= "login";
		public static const LOGIN_STATE:String			= "loginState";
		public static const LOGIN_SUCCESS:String		= "loginSuccess";
		public static const LOGIN_FAIL:String			= "loginFail";
		public static const LOGIN_UNABLE:String			= "loginUnable";
		public static const LOGOUT:String				= "logOut";
		public static const REGISTER:String				= "register";
		public static const REGISTER_USER_EXIT:String	= "registerUserExit";
		public static const REGISTER_COMPLETE:String	= "registerComplete";
		public static const DELETE_ACCOUNT:String		= "deleteAccount";
		public static const SETTING_UPDATE:String		= "settingUpdate";
		public static const	SETTING_PASSWORD:String		= "settingPassword";
		public static const NEW_USER_DATA:String		= "newUserData";
		
		//data
		public static const DATA_ERROR:String			= "dataError";
		public static const FETCH_SERVICES:String		= "fetchServices";
		public static const CREATE_LABEL_TREE:String	= "creatLabelTree";
		public static const LABEL_TREE_CREATE:String	= "labelTreeCreat";
		public static const USER_IS_LABEL_NEW:String 	= "userIsLabelNew";
		public static const BLOG_SUMMARY_SHOW:String	= "blogSummaryShow";
		public static const BLOG_SUMMARY_CREATE:String 	= "blogSummaryCreate";
		public static const BLOG_FETCH:String			= "blogFetch";
		public static const BLOG_FETCH_COMPLETE:String	= "blogFetchComplete";
		public static const BLOG_FETCH_NULL:String		= "blogFetchNull";
		public static const BLOG_FETCH_ALL:String		= "blogFetchAll";
		public static const BLOG_SEARCH_RESULT:String	= "blogSearchResult";
		public static const REMOVED_SUBSCRIBE:String	= "removedSubscribe";
		public static const REMOVED_LABEL:String		= "removedLabel";
		public static const COUNT_DATA:String			= "countData";
		
		//draft
		public static const DRAFT_ALL:String			= "draftFetchAll";
		public static const DRAFT_UNPUBED_OK:String		= "draftFetchUnpublishedOk";
		public static const DRAFT_PUBED_OK:String		= "draftFetchPublishedOk"; 
		public static const DRAFT_PUBLISHED:String		= "draftPublished";
		public static const DRAFT_UPDATE_PUBED:String	= "draftUpdatePublished";
		public static const COUNT_DRAFT:String			= "countDraft";
		public static const MEDIA_ALL:String			= "mediaFetchAll";
		
		//title window
		public static const LABEL_CREATE:String			= "labelCreate";
		public static const SUBSCRIBE_CREATE:String		= "subscribeCreate";
		public static const SEARCH_SUBSCRIBE:String		= "searchSubscribe";
		public static const RENAME_SUBSCRIBE:String		= "renameSubscribe";
		public static const REMOVE_SUBSCRIBE:String		= "removeSubscribe";
		public static const REMOVE_LABEL:String			= "removeLabel";
		public static const SERVICE_SUBSCRIBES:String	= "serviceSubscribes";
		public static const VIEW_START_UP:String		= "viewStartUp";
		
		//search feeds
		public static const SEARCH_FEED:String			= "searchFeeds";
		public static const FEEDS_SEARCHED:String		= "feedsSearched";
		
		//open blog writer
		public static const WRITER_OPEN:String			= "openWriter";
		public static const WRITER_CLOSE:String 		= "closeWriter";
		public static const WRITER_VIEW_CHANGE:String	= "writerViewChange";
		
		//open setting panel
		public static const SETTING_OPEN:String			= "settingOpen";
		
		//open air explorer
		public static const AIR_EXPLORER_OPEN:String	= "airExplorerOpen";
		
		//write blog
		public static const INSERT_PHOTOS:String		= "insertPhotos";
		public static const INSERT_PHOTOS_HTML:String	= "insertPhotosHtml";
		public static const OPEN_GET_PHOTO:String		= "openGetPhoto";
		public static const PHOTO_FILE_DATA:String		= "photoFileData";
		public static const GET_ALBUMS:String			= "getAlbums";
		public static const GET_ALBUM_PHOTOS:String		= "getAlbumPhotos";
		public static const GET_PHOTOS:String			= "getPhotos";
		public static const GET_PHOTO:String			= "getPhoto";
		public static const UPLOAD_PHOTO:String			= "uploadPhoto";
		public static const SERVICE_ERROR:String		= "serviceError";
		public static const EDIT_DRAFT:String			= "editDraft";
		
		//auto-save blog
		public static const AUTOSAVE_CHANGE:String		= "autoSaveChange";
		public static const AUTOSAVE_SAVE:String		= "autoSaveSave";
		public static const AUTOSAVE_READ:String		= "autoSaveRead";
		public static const AUTOSAVE_READ_OK:String		= "autoSaveReadOK";
		public static const AUTOSAVE_READ_NULL:String	= "autoSaveReadNull";
		public static const AUTOSAVE_CLEAR:String		= "autoSaveClear";
		
		//auth window
		public static const OPEN_AUTH_WINDOW:String		= "openAuthWindow";
		
		//OPML
		public static const OPML_EXECUTE:String			= "opmlExecute";
		
		//////////////////////////////////////////////////////////////////////////////
		//Multiton ApplicationFacade Factory Method
		
		public function ApplicationFacade()
		{
			super(NAME);
		}
		
		public static function getInstance():ApplicationFacade
		{
			if (instanceMap[NAME] == null ) instanceMap[NAME] = new ApplicationFacade();
            return instanceMap[NAME] as ApplicationFacade;
		}
		
		//////////////////////////////////////////////////////////////////////////////
		//methods
		
		public function startup( app:Reader ):void
		{
			ToolTipManager.toolTipClass = HtmlToolTip;
			sendNotification( STARTUP, app );
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			
			registerCommand(CHANGE_SCREEN, ScreenCommand);
			registerCommand(DATA_ERROR, DataErrorCommand);
			registerCommand(STARTUP, StartUpCommand);
			registerCommand(RESOURCE_LOAD, LoginCommand);
			registerCommand(LOGIN_SUCCESS, InitDataCommand);
			registerCommand(SETTING_OPEN, SettingPanelCommand);
			registerCommand(AIR_EXPLORER_OPEN, OpenExplorerCommand);
			registerCommand(WRITER_OPEN, OpenWriterCommand);
			registerCommand(REQUEST_USERCONFIRM, UserConfirmCommand);
			registerCommand(LOGOUT, LoginOutCommand);
			registerCommand(UPDATE_READER, AutoUpdateCommand);
			registerCommand(SHOW_ABOUT, AboutMeCommand);
			registerCommand(TRAY_DOCK, TrayCommand);
			registerCommand(CLOSE_WINDOW, CloseCommand);
		}
		
	}
}